package com.atguigu.jucdemo.test;

public class SaleTicketDemo implements Runnable{

    int ticket = 50;//100张票
    Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(100L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "...买了第" + ticket + "张票");
                    ticket--;
                }
            }

        }
    }
}
